<?PHP

	include("../includes/configPages.php");
	
	if($_GET['args']!="null"){

		if(is_numeric($_GET['args'])){
			if($users->auth($db, 4)){
			
				/* list variables */
				
				$user = $users->getUser($db, $_GET['args']);
				
				/* common info */
				$variableStack['commonPanel'] = "";
				$variableStack['contactPanel'] = "";
				while($row = mysql_fetch_object($user)){
					$variableStack['profileTitle'] = sprintf($lang['members_list_viewing_title'], $row->username);
					$variableStack['avatar'] = $row->user_avatar;
					
					$htmlPanel = file_get_contents('../styles/'.$activeStyle.'/t/memberlist-item.html');	
					
					$panelVariableStack['data'] = stripslashes($row->username);
					$panelVariableStack['text'] = $lang['members_list_viewing_username'];
					$variableStack['commonPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					
					$panelVariableStack['data'] = stripslashes($row->rankname);
					$panelVariableStack['text'] = $lang['members_list_viewing_rank'];
					$variableStack['commonPanel'] .= parseHtml($htmlPanel, $panelVariableStack);
					
					if(strlen($row->rname)>0){
						$panelVariableStack['data'] = stripslashes($row->rname);
						$panelVariableStack['text'] = $lang['members_list_viewing_name'];
						$variableStack['commonPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->location)>0){
						$panelVariableStack['data'] = stripslashes($row->location);
						$panelVariableStack['text'] = $lang['members_list_viewing_location'];
						$variableStack['commonPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->age)>0){
						$panelVariableStack['data'] = stripslashes($row->age);
						$panelVariableStack['text'] = $lang['members_list_viewing_age'];
						$variableStack['commonPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->occupation)>0){
						$panelVariableStack['data'] = stripslashes($row->occupation);
						$panelVariableStack['text'] = $lang['members_list_viewing_occupation'];
						$variableStack['commonPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->interests)>0){
						$panelVariableStack['data'] = stripslashes($row->interests);
						$panelVariableStack['text'] = $lang['members_list_viewing_interests'];
						$variableStack['commonPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}
					
					/* contact info */
					if(strlen($row->contact_msn)>0){
						$panelVariableStack['data'] = stripslashes($row->contact_msn);
						$panelVariableStack['text'] = $lang['members_list_viewing_msn'];
						$variableStack['contactPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->contact_icq)>0){
						$panelVariableStack['data'] = stripslashes($row->contact_icq);
						$panelVariableStack['text'] = $lang['members_list_viewing_icq'];
						$variableStack['contactPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->contact_jabber)>0){
						$panelVariableStack['data'] = stripslashes($row->contact_jabber);
						$panelVariableStack['text'] = $lang['members_list_viewing_jabber'];
						$variableStack['contactPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->contact_gchat)>0){
						$panelVariableStack['data'] = stripslashes($row->contact_gchat);
						$panelVariableStack['text'] = $lang['members_list_viewing_gchat'];
						$variableStack['contactPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->contact_yim)>0){
						$panelVariableStack['data'] = stripslashes($row->contact_yim);
						$panelVariableStack['text'] = $lang['members_list_viewing_yim'];
						$variableStack['contactPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}

					if(strlen($row->contact_website)>0){
						$panelVariableStack['data'] = stripslashes($row->contact_website);
						$panelVariableStack['text'] = $lang['members_list_viewing_website'];
						$variableStack['contactPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
					}
					
				}
				
				
				
				
				/* custom fields */
				$userFields = $users->getUserCustomFields($db, $_GET['args']);
				$variableStack['miscPanel'] = "";
				if($userFields){
					while($row = mysql_fetch_object($userFields)){
						if($row->field_enabled==1 && $row->field_viewable==1){
							if(strlen($row->field_data_value)>0){
								$panelVariableStack['data'] = $row->field_data_value;
								$panelVariableStack['text'] = $row->field_name;
								$variableStack['miscPanel'] .= parseHtml($htmlPanel, $panelVariableStack);	
							}							
						}
					}
				}
				
				/* signature */
				$userSig = $users->getSignature($db, $_GET['args']);
				if($userFields){
					while($row = mysql_fetch_object($userSig)){
						$variableStack['signature'] = $row->sig_html;	
					}
				}

				$html = file_get_contents('../styles/'.$activeStyle.'/t/memberlist-view.html');	
				echo parseHtml($html, $variableStack);	
				
			} else {
		
				echo "<script>fetchPage('login' ,null)</script>";
				
			}
		} else {
			echo $lang['members_list_invalid_user'];
		}
		
	} else {
		$outHtml = "";
		$result = $users->getAllUsers($db);
		$count = 1;
		$outHtml .= '<div class="result">';
		while($row = mysql_fetch_object($result)){
			if($count % 10 ==0){
				$outHtml .= '</div>';
				$outHtml .= '<div class="result">';
			}
			$itemVariableStack['username'] = $row->username;
			$itemVariableStack['rank'] = $row->rankname;
			$itemVariableStack['userid'] = $row->userid;
			$itemVariableStack['website'] = $row->contact_website;
			$itemVariableStack['location'] = $row->location;
			if($row->rankcolour!=NULL){
				$itemVariableStack['rank_colour'] = $row->rankcolour;
			} else {
				$itemVariableStack['rank_colour'] = $row->colour;
			}
			$postcount = $users->getPostCount($db, $row->userid);
			$itemVariableStack['postcount'] = $postcount;
			$htmlItem = file_get_contents('../styles/'.$activeStyle.'/t/memberlist-all-item.html');	
			$outHtml .=  parseHtml($htmlItem, $itemVariableStack);
			$count++;
		}
		$outHtml .= '</div>';
		
		$variableStack['members_title'] = $lang['members_list_title'];
		$variableStack['list_html'] = $outHtml;
		$html = file_get_contents('../styles/'.$activeStyle.'/t/memberlist-all.html');	
		echo parseHtml($html, $variableStack);
		
	}

?>